package com.example.grpc.generator;

import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;

/**
 * <pre>
 * 最后，让我们定义服务(method)。对于我们的 HelloService，
 * 我这里定义了一个 hello() 操作：单次接受一个请求并返回一个响应
 * </pre>
 */
@javax.annotation.Generated(
    value = "by gRPC proto compiler (version 1.4.0)",
    comments = "Source: HelloService.proto")
public final class HelloServiceGrpc {

    private HelloServiceGrpc() {
    }

    public static final String SERVICE_NAME = "com.example.grpc.generator.HelloService";

    // Static method descriptors that strictly reflect the proto.
    @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
    public static final io.grpc.MethodDescriptor<HelloRequest,
        HelloResponse> METHOD_HELLO =
        io.grpc.MethodDescriptor.<HelloRequest, HelloResponse>newBuilder()
            .setType(io.grpc.MethodDescriptor.MethodType.UNARY)
            .setFullMethodName(generateFullMethodName(
                "com.example.grpc.generator.HelloService", "hello"))
            .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                HelloRequest.getDefaultInstance()))
            .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                HelloResponse.getDefaultInstance()))
            .build();

    /**
     * Creates a new async stub that supports all call types for the service
     */
    public static HelloServiceStub newStub(io.grpc.Channel channel) {
        return new HelloServiceStub(channel);
    }

    /**
     * Creates a new blocking-style stub that supports unary and streaming output calls on the service
     */
    public static HelloServiceBlockingStub newBlockingStub(
        io.grpc.Channel channel) {
        return new HelloServiceBlockingStub(channel);
    }

    /**
     * Creates a new ListenableFuture-style stub that supports unary calls on the service
     */
    public static HelloServiceFutureStub newFutureStub(
        io.grpc.Channel channel) {
        return new HelloServiceFutureStub(channel);
    }

    /**
     * <pre>
     * 最后，让我们定义服务(method)。对于我们的 HelloService，
     * 我这里定义了一个 hello() 操作：单次接受一个请求并返回一个响应
     * </pre>
     */
    public static abstract class HelloServiceImplBase implements io.grpc.BindableService {

        /**
         *
         */
        public void hello(HelloRequest request,
                          io.grpc.stub.StreamObserver<HelloResponse> responseObserver) {
            asyncUnimplementedUnaryCall(METHOD_HELLO, responseObserver);
        }

        @Override
        public final io.grpc.ServerServiceDefinition bindService() {
            return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
                .addMethod(
                    METHOD_HELLO,
                    asyncUnaryCall(
                        new MethodHandlers<
                            HelloRequest,
                            HelloResponse>(
                            this, METHODID_HELLO)))
                .build();
        }
    }

    /**
     * <pre>
     * 最后，让我们定义服务(method)。对于我们的 HelloService，
     * 我这里定义了一个 hello() 操作：单次接受一个请求并返回一个响应
     * </pre>
     */
    public static final class HelloServiceStub extends io.grpc.stub.AbstractStub<HelloServiceStub> {
        private HelloServiceStub(io.grpc.Channel channel) {
            super(channel);
        }

        private HelloServiceStub(io.grpc.Channel channel,
                                 io.grpc.CallOptions callOptions) {
            super(channel, callOptions);
        }

        @Override
        protected HelloServiceStub build(io.grpc.Channel channel,
                                         io.grpc.CallOptions callOptions) {
            return new HelloServiceStub(channel, callOptions);
        }

        /**
         *
         */
        public void hello(HelloRequest request,
                          io.grpc.stub.StreamObserver<HelloResponse> responseObserver) {
            asyncUnaryCall(
                getChannel().newCall(METHOD_HELLO, getCallOptions()), request, responseObserver);
        }
    }

    /**
     * <pre>
     * 最后，让我们定义服务(method)。对于我们的 HelloService，
     * 我这里定义了一个 hello() 操作：单次接受一个请求并返回一个响应
     * </pre>
     */
    public static final class HelloServiceBlockingStub
        extends io.grpc.stub.AbstractStub<HelloServiceBlockingStub> {
        private HelloServiceBlockingStub(io.grpc.Channel channel) {
            super(channel);
        }

        private HelloServiceBlockingStub(io.grpc.Channel channel,
                                         io.grpc.CallOptions callOptions) {
            super(channel, callOptions);
        }

        @Override
        protected HelloServiceBlockingStub build(io.grpc.Channel channel,
                                                 io.grpc.CallOptions callOptions) {
            return new HelloServiceBlockingStub(channel, callOptions);
        }

        /**
         *
         */
        public HelloResponse hello(HelloRequest request) {
            return blockingUnaryCall(
                getChannel(), METHOD_HELLO, getCallOptions(), request);
        }
    }

    /**
     * <pre>
     * 最后，让我们定义服务(method)。对于我们的 HelloService，
     * 我这里定义了一个 hello() 操作：单次接受一个请求并返回一个响应
     * </pre>
     */
    public static final class HelloServiceFutureStub
        extends io.grpc.stub.AbstractStub<HelloServiceFutureStub> {
        private HelloServiceFutureStub(io.grpc.Channel channel) {
            super(channel);
        }

        private HelloServiceFutureStub(io.grpc.Channel channel,
                                       io.grpc.CallOptions callOptions) {
            super(channel, callOptions);
        }

        @Override
        protected HelloServiceFutureStub build(io.grpc.Channel channel,
                                               io.grpc.CallOptions callOptions) {
            return new HelloServiceFutureStub(channel, callOptions);
        }

        /**
         *
         */
        public com.google.common.util.concurrent.ListenableFuture<HelloResponse> hello(
            HelloRequest request) {
            return futureUnaryCall(
                getChannel().newCall(METHOD_HELLO, getCallOptions()), request);
        }
    }

    private static final int METHODID_HELLO = 0;

    private static final class MethodHandlers<Req, Resp> implements
        io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
        io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
        io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
        io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
        private final HelloServiceImplBase serviceImpl;
        private final int methodId;

        MethodHandlers(HelloServiceImplBase serviceImpl, int methodId) {
            this.serviceImpl = serviceImpl;
            this.methodId = methodId;
        }

        @Override
        @SuppressWarnings("unchecked")
        public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
            switch (methodId) {
                case METHODID_HELLO:
                    serviceImpl.hello((HelloRequest) request,
                        (io.grpc.stub.StreamObserver<HelloResponse>) responseObserver);
                    break;
                default:
                    throw new AssertionError();
            }
        }

        @Override
        @SuppressWarnings("unchecked")
        public io.grpc.stub.StreamObserver<Req> invoke(
            io.grpc.stub.StreamObserver<Resp> responseObserver) {
            switch (methodId) {
                default:
                    throw new AssertionError();
            }
        }
    }

    private static final class HelloServiceDescriptorSupplier
        implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
        @Override
        public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
            return HelloServiceOuterClass.getDescriptor();
        }
    }

    private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

    public static io.grpc.ServiceDescriptor getServiceDescriptor() {
        io.grpc.ServiceDescriptor result = serviceDescriptor;
        if (result == null) {
            synchronized (HelloServiceGrpc.class) {
                result = serviceDescriptor;
                if (result == null) {
                    serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
                        .setSchemaDescriptor(new HelloServiceDescriptorSupplier())
                        .addMethod(METHOD_HELLO)
                        .build();
                }
            }
        }
        return result;
    }
}
